/**业务管理流程平台版本1.0,生成时间:2017-04-13 13:16:48**/
package com.xbdun.dao.bmp.mapper;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.xbdun.dao.bmp.dto.OrleDepartDto;
import com.xbdun.dao.bmp.entity.XbdunOrleDepartDo;
import com.xbdun.dao.bmp.provider.OrleDepartSqlProvider;


/**
 * 部门角色中间表
 * @author 张国涛
 * @2017-04-13 13:16:48
 */
@Mapper
public interface OrleDepartMapper{

	/**
	 * 根据主键获取对象
	 * @return
	 */
	@Select("SELECT * FROM xbdun_orle_depart where id=#{id} AND orgCode = ${orgCode}")
	public XbdunOrleDepartDo getXbdunOrleDepartById(@Param("id")long id,@Param("orgCode")long orgCode);
	
	/**
	 * 删除数据根据主键
	 * @param id
	 */
	@Delete("DELETE FROM xbdun_orle_depart WHERE id = #{id} AND orgCode =${orgCode} AND version=#{version}")
	public int delXbdunOrleDepartById(@Param("id")long id,@Param("orgCode")long orgCode,@Param("version")Timestamp version);
	
	/**
	 * 判断是否存在,不为null则是存在
	 * @param param
	 * @return Long
	 */
	@SelectProvider(type=OrleDepartSqlProvider.class,method="existSql")
	public Long existXbdunOrleDepart(@Param("param")Map<String,Object> param);
	/**
	 * 动态更新参数,参数中Map可以必须跟Key为Where的更新条件<br/>
	 * <pre>
	 * 	例如：
	 *  Map<String,Object> setting = new HashMap<String,Object>();
	 *  setting.put("email", "360730440@qq.com");
	 *
	 *  Map<String,Object> where = new HashMap<String,Object>();
	 *  where.put("userId", "1222");
	 * </pre>
	 * Map的key值就是数据库字段<br/>
	 * Map的value就是值
	 */
	@UpdateProvider(type=OrleDepartSqlProvider.class,method="updateDynXbdunOrleDepartSql")
	public void updateDynXbdunOrleDepart(@Param("param")Map<String,Object> param,@Param("_where")Map<String,Object> where);
	
	//------------------------//start分页查询--------------------------------------
	/**
	* @Title: queryPager
	* @Description: 分页查询
	* @param orgCode
	* @param orderBy
	* @param pageIndex
	* @param pageSize
	* @return List<OrleDepartDto>    返回类型
	 */
	@SelectProvider(type=OrleDepartSqlProvider.class,method="queryPagerSql")
	public List<OrleDepartDto> queryPager(@Param("orgCode")Long orgCode,@Param("userCode")Long userCode,@Param("departCode")Long departCode,@Param("pageIndex")int pageNum,@Param("pageSize")int numPerPage);
	
	/**
	* @Title: queryPagerCount
	* @Description: 分页查询
	* @param orgCode
	* @return Long    返回类型
	 */
	@Select("SELECT COUNT(*) FROM xbdun_orle_depart WHERE orgCode = #{orgCode} AND code = #{departCode}")
	public Long queryPagerCount(@Param("orgCode")Long orgCode, @Param("departCode")Long departCode);
	//-------------------------//end--------------------------------------------

	/**
	* @Title: addOrleDeparts
	* @Description: 新增部门关联角色
	* @param xbdunOrleDepartDo
	* @param roleId
	* @return    设定文件
	* @return int    返回类型
	 */
	@InsertProvider(type=OrleDepartSqlProvider.class,method="addOrleDepartsSql")
	public int addOrleDeparts(@Param("a")XbdunOrleDepartDo xbdunOrleDepartDo,@Param("list")List<Long> roleId);
	
	/**
	* @Title: existDepartRoles
	* @Description: 判断机构部门下是否还存在角色
	* @param code		部门编号
	* @param orgCode	机构编号
	* @return int    返回类型
	 */
	@Select("SELECT COUNT(*) FROM xbdun_orle_depart WHERE orgCode=${orgCode} AND code =${code}")
	public int existDepartRoles(@Param("code")long code,@Param("orgCode")long orgCode);
	/**
	* @Title: existDepartRoleId
	* @Description 判断机构对应的Id是否存在
	* @param id
	* @param orgCode
	* @return    设定文件
	* @return int    返回类型
	 */
	@Select("SELECT COUNT(*) FROM xbdun_orle_depart WHERE id=${roleDepartId} AND orgCode =${orgCode}")
	public int existDepartRoleId(@Param("roleDepartId")long id,@Param("orgCode")long orgCode);
	
	/**
	* @Title: chekRoleDepartOk
	* @Description	检测机构下部门对应的角色是否合法
	* @param orgCode		机构编号
	* @param departCode		部门编号
	* @param roleDptIds		部门关联下的角色
	* @return int    返回总共的关联ID是否数量相同
	 */
	@SelectProvider(type=OrleDepartSqlProvider.class,method="chekRoleDepartOkSql")
	public int chekRoleDepartOk(@Param("orgCode")long orgCode,@Param("departCode")long departCode,@Param("roleDptIds")Set<Long> roleDptIds);
}